<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
  <head>
    <base href="<%=basePath%>">
	<%@ include file="/base/jsp/include.jsp"%>
	<script type="text/javascripthttp://dns.www.net.cn/static/images/loading.gif">
	</script>
	<style type="text/css">
		.orderInput {
			width: 200px;
			border: none;
		}
	</style>
  </head>
  <body>
    <form id="form" method="post">
        <input name="id" class="mini-hidden" />
        <fieldset id="forPrint" style="border:solid 1px #aaa;">
            <legend >订单信息</legend>
            <div>
            <table>
            	<tr>
                    <td style="width:150px; height: 40px; font-size:9px;">订单号：</td>
                    <td style="width:150px;">
                    	<span style="font-size: 9px;" class="info-text" id="id"></span>
                    </td>
                </tr>
            	<tr>
                    <td style="width:150px; height: 40px; font-size:9px;">姓名：</td>
                    <td style="width:150px;">
                    	<span style="font-size: 9px;" class="info-text" id="username"></span>
                    </td>
                </tr>
                <tr>
                    <td style="width:150px; height: 40px; font-size:9px;">电话：</td>
                    <td style="width:150px;">
                    	<span style="font-size: 9px;" id="phone"></span>
                    </td>
                </tr>
                <tr>
                    <td style="width:150px; height: 40px; font-size:9px;">地址：</td>
                    <td style="width:150px;">
                    	<span style="font-size: 9px;" id="address"></span>	
                    </td>
                </tr>
                <tr>
                    <td style="width:150px; height: 40px; font-size:9px;">时间：</td>
                    <td style="width:150px;">
                    	<span style="font-size: 9px;" id="createTime"></span>	
                    </td>
                </tr>
                <tr>
                    <td style="width:150px; height: 40px; font-size:9px;">总金额：</td>
                    <td style="width:150px;">
                    	<span style="font-size: 9px;" id="totalMoney"></span>	
                    </td>
                </tr>
            </table>   
            <table id="orderItems">
            	<tr>
            		<td style="width:200px;">商品名</td>
            		<td style="width:200px;">数量</td>
            		<td style="width:200px;">单价</td>
            	</tr>
            	<tr class="orderItem" style="display: none;">
            		<td class="bookname" style="width:200px;">1</td>
            		<td class="count" style="width:200px;">1</td>
            		<td class="price" style="width:200px;">1</td>
            	</tr>
            </table>         
         </div>
        </fieldset>
        
        <div style="text-align:center;padding:10px;">
            <a class="mini-button" onclick="onCancel" style="width:60px;margin-right:20px;">确定</a>
            <a class="mini-button" onclick="onPrint" style="width:60px;">打印</a>       
        </div>        
    </form>
    <script type="text/javascript">
    	var id = '';
        mini.parse();
       
        //标准方法接口定义
        function SetData(data) {
            if (data.action == "show") {
            	$('#pwdTr').hide();
                //跨页面传递的数据对象，克隆后才可以安全使用
                data = mini.clone(data);
                $.ajax({
                    url: "findByIdOrder.do?id=" + data.id,
                    cache: false,
                    success: function (text) {
                        var o = mini.decode(text,true);
                        id = o.id;
                        $('#id').text(o.id);
                        $('#username').text(o.username);
                        $('#name').text(o.name);
                        $('#phone').text(o.phone);
                        $('#address').text(o.address);
                        $('#createTime').text(timeStamp2String(o.createTime));
                   	
               			var items = o.items;
               			var itemO = $('.orderItem').eq(0);
               			var itemTb = $('#orderItems');
               			var totalMoney = 0;
               			for(var i = 0, len = items.length; i < len; i++) {
               				var itemTr = itemO.clone();
               				itemTr.css('display', '');
               				itemTr.find('.bookname').text(items[i].bookName);
               				itemTr.find('.count').text(items[i].count);
               				itemTr.find('.price').text(items[i].price);
               				totalMoney += items[i].count * items[i].price;
               				itemTb.append(itemTr);
               			}
               			$('#totalMoney').text(totalMoney);
                    }
                });
            }
        }

        function GetData() {
            var o = form.getData(true);
            return o;
        }
        function CloseWindow(action) {
            if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
            else window.close();            
        }
        function onOk(e) {
            SaveData();
        }
        function onCancel(e) {
            CloseWindow("cancel");
        }
        function onPrint() {
        	$('#forPrint').jqprint();
        }
        
        function timeVailidation(e){
        	var pattern = /^\d{2}:\d{2}/;
        	if (e.isValid) {
        		if(e.value.search(pattern) == -1){
        			e.errorText = "日期格式错误";
                    e.isValid = false;
                }
            }
        }
        
        function timeStamp2String(date){
	var datetime = date;
	//datetime.setTime(time);
	 	var year = datetime.getFullYear();
	var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
	var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
	var hour = datetime.getHours()< 10 ? "0" + datetime.getHours() : datetime.getHours();
	var minute = datetime.getMinutes()< 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
	var second = datetime.getSeconds()< 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
	return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second;
}
       
    </script>	
     <script src="${path}/base/js/timeFormat.js"></script>
     <script type="text/javascript" src="${path}/base/js/jquery.jqprint-0.3.js"></script>
  </body>
</html>
